package com.fin.zw.intelligentbot.entity;

import com.fin.zw.intelligentbot.enums.TaskStatus;
import com.fin.zw.intelligentbot.enums.Whether;
import lombok.Data;
import org.hibernate.annotations.Table;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

@Entity
@Table(appliesTo = "dial_task",comment="任务信息")
@Data
public class DialTask extends BaseEntity{

    @Column(columnDefinition = "varchar(50) comment '任务名称'")
    private String name;

    @Column(columnDefinition = "int(10) comment '客户数量'")
    private Integer count = 0;

    @Column(columnDefinition = "varchar(20) comment '任务状态'")
    @Enumerated(EnumType.STRING)
    private TaskStatus status;

    @Column(columnDefinition = "varchar(20) comment '是否是自动任务'")
    @Enumerated(EnumType.STRING)
    private Whether autoType = Whether.NO;

    @Column(columnDefinition = "datetime COMMENT '开始时间'")
    private Date startTime;

    @Column(columnDefinition = "datetime COMMENT '结束时间'")
    private Date endTime;

    @Column(columnDefinition = "datetime COMMENT '创建时间'")
    private Date createTime;

    @Column(columnDefinition = "datetime COMMENT '定时任务时间'")
    private Date timing;

    @Column(columnDefinition = "varchar(64) COMMENT '创建人id'")
    private String createId;

    @Column(columnDefinition = "int(10) comment '自动回收次数'")
    private Integer recoveryCount = 0;

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id",columnDefinition = "varchar(64) COMMENT '企业id'")
    private Company company;

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinColumn(name = "strategy_id", columnDefinition = "varchar(64) COMMENT '策略id'")
    private StrategyInfo strategyInfo;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "sce_id",columnDefinition = "varchar(64) COMMENT '场景id'")
    private SceneInfo scene;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "task_bot", joinColumns = @JoinColumn(name = "task_id"), inverseJoinColumns = @JoinColumn(name = "bot_id"))
    private Set<RobotInfo> robots;

    @JoinColumn(name = "customer_file_id",columnDefinition = "varchar(64) COMMENT '客户数据文件id'")
    @OneToOne(fetch = FetchType.EAGER)
    private UploadFile CustomerDataFile;

    @Column(columnDefinition = "varchar(64) COMMENT '初始创建的任务id'")
    private String initId;

    @Column(columnDefinition = "varchar(64) COMMENT '上级id'")
    private String parentId;
}
